let defaultCachePrefix = '20180428_'; // 默认缓存前缀,便于快速清除缓存
export const setCatchePrefix = (prefix) => {
  defaultCachePrefix = `${prefix}_`;
};
const TOKEN = 'token';

/**
 * 获取token
 * @param forHeader
 * @returns {*}
 */
export function getToken() {
  const token = sessionStorage[TOKEN] || localStorage[TOKEN];
  return token;
}
/**
 * 保存token
 * @param token
 * @param remeber
 */
export function saveToken(token, remeber) {
  const store = remeber ? localStorage : sessionStorage;
  if (token === null || token === undefined) {
    store.removeItem(TOKEN);
  } else {
    store[TOKEN] = token;
  }
}
export const saveStorage = (key, value, remeber) => {
  (remeber ? localStorage : sessionStorage)[`${defaultCachePrefix}${key}`] = value;
};
export const getStorage = (key) =>
  sessionStorage[`${defaultCachePrefix}${key}`] || localStorage[`${defaultCachePrefix}${key}`];

export function removeStorage() {
  sessionStorage.clear();
  localStorage.clear();
}
